<template>
    <div class="box">
        <el-card class="box-card">
            <h1>登录</h1>
            <el-form
                :label-position="labelPosition"
                label-width="100px"
                :model="formLabelAlign"
                style="max-width: 460px"
            >
                <el-form-item label="用户名">
                <el-input  v-model="formLabelAlign.account" />
                </el-form-item>
                <el-form-item label="密码">
                <el-input  v-model="formLabelAlign.passWord" />
                </el-form-item>
                
                <el-form-item>
                    <el-button type="primary" size=large @click="gologin">登录</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import type { FormProps } from 'element-plus'
import {reqLogin} from '@/api/user/index.ts'
import useUserStore from '@/store/modules/user'
import { useRouter } from 'vue-router';
import { ElNotification } from 'element-plus'
let $router = useRouter();
let useStore = useUserStore();
const labelPosition = ref<FormProps['labelPosition']>('right')

const formLabelAlign = reactive({
    account: '',
    passWord: '',
})
let loading = ref(false)
const gologin =async()=>{
    console.log(formLabelAlign);
    loading.value = true
    try {
        let result =await useStore.userLogin(formLabelAlign)
        $router.push("/")
        ElNotification({
        type:"success",
        message:"登录成功"
        });
        loading.value = false
    } catch (error) {
        loading.value = false
        ElNotification({
        type:"error",
        message:"登录失败"
        })
    }
    
    
}
</script>

<style scoped>
.box{
    width: 100%;
    height: 100vh;
    display:flex;
    justify-content: center;
    align-items: center;
    background-color:#708090;
}
.box-card {
    padding:20px;
  width: 480px;
}
.box-card h1{
    font-size:30px;
    line-height:40px;
}
</style>